<template>
  <div style="position: relative; height: 100%">
    <!--  维修报表  -->
<!--    <div class="top">
      <div class="l">
        <div style="display: flex; align-items: center">
          <span style="display: inline-block; width: 100px; color: #366">网关名</span>
          <el-input v-model="gatewayName" placeholder="请输入网关名"/>
          <el-date-picker
              v-model="logTime"
              type="datetimerange"
              range-separator="~"
              start-placeholder="起始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
              style="margin-left: 10px;"
          />
          <div class="def-btn" style="margin-left: 10px; margin-right: 30px" @click="searchHandle">搜索</div>
        </div>
      </div>
&lt;!&ndash;      <div class="r">
        <div class="sure-btn down-btn" @click="downLoadExcel">导出</div>
      </div>&ndash;&gt;
    </div>-->
    <div style="height: calc(100% - 90px)">
      <base-table :pagination="pagination" style="height: 100%"
                  @currentChange="currentChange">
        <el-table :data="tableData" stripe border
                  :cell-style="{ textAlign: 'center' }"
                  :header-cell-style="{ textAlign: 'center' }"
                  header-row-class-name="headerRow"
                  class="lamp-table"
                  style="width: 100%; height: calc(100% - 20px); overflow: auto">
          <el-table-column
              :width="item == '时间' ? '200px' : 'auto'"
              :prop="item"
              :label="item"
              v-for="(item, _index) in columnTitles"
              show-overflow-tooltip #default="scope">
            <span v-if="scope.row[`${item}`] == '离线' || scope.row[`${item}`] == '异常'" style="color: red">
              {{ scope.row[`${item}`] }}
            </span>
          </el-table-column>

<!--          <el-table-column type="index" width="150" label="序号" #default="scope">
            {{ scope.$index < 9 ? '0' + (scope.$index + 1) : scope.$index + 1 }}
          </el-table-column>
          <el-table-column prop="gatewayName" label="网关名"/>
          <el-table-column prop="message" label="维修信息"/>
          <el-table-column prop="creatTime" label="维修时间"/>-->
        </el-table>
      </base-table>
    </div>
  </div>
</template>

<script>
import {lampeRepairLogs,repairLogsChanged} from "../../router/api.js";
import {downBlobFile, downloadFile} from "../../util/index.js";
import BaseTable from "../../components/baseTable.vue";
export default {
  name: "maintenanceReport",
  components: { BaseTable },
  data() {
    return {
      gatewayName: '',
      pagination: {
        page: 1,
        size: 17,
        total: 0,
      },
      tableData: [],
      logTime: [],
      columnTitles: [],
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      let res = await repairLogsChanged({
        // startTimeStr: this.logTime[0],
        // endTimeStr: this.logTime[1],
        // gatewayName: this.gatewayName,
        page: this.pagination.page,
        size: this.pagination.size,
      })
      if (res.data.code == 200) {
        if ( res.data.data && res.data.data.records) {
          this.tableData = res.data.data.records;
          this.pagination.total = res.data.data.total;
          this.columnTitles = res.data.data.columnTitles;
        }
      } else {
        this.tableData = [];
        this.pagination.total = 0;
        // this.$message.warning(res.data.msg)
      }
    },
    downLoadExcel() {
      if(!this.logTime.length) return;
      downBlobFile('/api/opt/user/exportLogsByTime',{
        startTime: this.logTime[0],
        endTime: this.logTime[1],
      },`日志报表.xlsx`,'GET')
    },
    currentChange(val) {
      this.pagination.page = val;
      this.init();
    },
    searchHandle(){
      this.pagination.page = 1;
      this.init();
    }
  }
}
</script>

<style scoped lang="scss">
.down-btn:before {
  content: "\e60d";
}

.top {
  display: flex;
  justify-content: space-between;
  margin: 0 auto 20px;

  .l {
    display: flex;
    align-items: center;
  }

  .r {
    display: flex;

    .def-btn {
      width: initial;
      padding: 0 14px;
    }
  }
}
</style>
<style>
.headerRow {
  background: linear-gradient(to right, #6B92F0, #76D0FF) !important;
}

.el-table th.el-table__cell {
  background-color: transparent;
  color: #fff;
}

.el-table thead.is-group th.el-table__cell {
  background-color: transparent;
  color: #fff;
}
</style>
